package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.viewpager.widget.PagerAdapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/8/27 17:14
 * description:
 */
public class LoadingPageAdapter extends PagerAdapter {
    private int[] imgList = new int[]{};
    private Context ctx;

    public LoadingPageAdapter(Context ctx, int[] imgList, View imgVIew) {
        this.ctx = ctx;
        this.imgList = imgList;
        if(imgList.length==1)
            imgVIew.setVisibility(View.VISIBLE);
    }

    @Override
    public int getCount() {
        return imgList.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return (view == object);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imgView = new ImageView(ctx);
        imgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
        imgView.setLayoutParams(layoutParams);
        int imgId = imgList[position];
        if (imgId != 0) {
            imgView.setImageResource(imgId);
        }
        container.addView(imgView, 0);
        return imgView;
    }
}
